package com.example.manager.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.manager.entity.Student;
import com.example.manager.service.StudentService;

@RestController
public class StudentController {

	@Autowired
	private StudentService service;

	@GetMapping("students")
	public List<Student> getAllStudents() {
		return service.getAllStudent();
	}

	@GetMapping("students/{sid}")
	public Student getStudentBySid(@PathVariable String sid) {
		return service.getStudentBySid(sid);
	}

	@PutMapping("students/{sid}")
	public String editStudent(@PathVariable String sid, Student stu) {
		//stu.setSid(sid);
		return service.editStudent(stu);
	}
	
	@PostMapping("students")
	public String saveStudent(Student stu) {
		return service.addStudent(stu);
	}
	
	@DeleteMapping("students/{sid}")
	public String delStudent(@PathVariable String sid) {
		return service.deleteStudent(sid);
	}
}
